<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"
            "http://www.w3.org/TR/REC-html40/loose.dtd">
<HTML>
<HEAD>



<META http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<META name="GENERATOR" content="hevea 1.08">
<LINK rel="stylesheet" type="text/css" href="tutorial.css">
<TITLE>
Working with Arrays of Items
</TITLE>
</HEAD>
<BODY >
<A HREF="tutorial025.html"><IMG SRC ="previous_motif.gif" ALT="Previous"></A>
<A HREF="tutorial023.html"><IMG SRC ="contents_motif.gif" ALT="Up"></A>
<A HREF="tutorial027.html"><IMG SRC ="next_motif.gif" ALT="Next"></A>
<HR>

<H2 CLASS="section"><A NAME="htoc54">4.3</A>&nbsp;&nbsp;Working with Arrays of Items</H2>
For convenience, ECL<SUP><I>i</I></SUP>PS<SUP><I>e</I></SUP> has some features for facilitating working with
arrays of items.
Arrays can be of any dimension, and can be declared with the
<A HREF="../bips/kernel/termmanip/dim-2.html"><B>dim/2</B></A><A NAME="@default85"></A>
predicate:
<BLOCKQUOTE CLASS="quote"><PRE CLASS="verbatim">
?- dim(M,[3,4]).
M = []([](_131, _132, _133, _134),
       [](_126, _127, _128, _129),
       [](_121, _122, _123, _124))
yes.
</PRE></BLOCKQUOTE>
<A HREF="../bips/kernel/termmanip/dim-2.html"><B>dim/2</B></A><A NAME="@default86"></A> can also be used to
query the dimensions of an array:
<BLOCKQUOTE CLASS="quote"><PRE CLASS="verbatim">
?- dim(M,[3,4]), dim(M,D).
...
D = [3, 4]
yes.
</PRE></BLOCKQUOTE>

<TABLE CELLPADDING=10>
<TR><TD BGCOLOR="#CCFFCC">
<DL CLASS="description" COMPACT=compact><DT CLASS="dt-description">
<B>&otimes;</B><DD CLASS="dd-description"> Note that arrays are just structures, and that the functor is not
important.
</DL>
</TD>
</TR></TABLE>
<BR>
To access a specific element of an array in an expression, specify the index
list of the desired element, e.g.
<BLOCKQUOTE CLASS="quote"><PRE CLASS="verbatim">
?- M = []([](2, 3, 5),
          [](1, 4, 7)),  X is M[1, 2] + M[2, 3].
X = 10
M = []([](2, 3, 5), [](1, 4, 7))
yes.
</PRE></BLOCKQUOTE>

	<BLOCKQUOTE CLASS="figure"><DIV CLASS="center"><HR WIDTH="80%" SIZE=2></DIV>
	<DIV CLASS="center">
	<TABLE CELLPADDING=10>
<TR><TD BGCOLOR="#DB9370">
	
<UL CLASS="itemize"><LI CLASS="li-itemize">
Arrays are just structures
<LI CLASS="li-itemize">The functor is not important
<LI CLASS="li-itemize">Declare or query array size with
 <A HREF="../bips/kernel/termmanip/dim-2.html"><B>dim/2</B></A><A NAME="@default87"></A>
<LI CLASS="li-itemize">Access elements in expressions by specifying their index list
 (e.g. <TT>A[7]</TT>, <TT>M[2,3]</TT>)
<LI CLASS="li-itemize">Indices start at 1
</UL>

	</TD>
</TR></TABLE>
	</DIV>
	<BR>
<BR>
<DIV CLASS="center">Figure 4.2: Array notation</DIV><BR>
<BR>

	<DIV CLASS="center"><HR WIDTH="80%" SIZE=2></DIV></BLOCKQUOTE>
<DL CLASS="description" COMPACT=compact><DT CLASS="dt-description">
<B>&#8857;</B><DD CLASS="dd-description"> <FONT COLOR="#9832CC">For further details see the Array Notation section of the User Manual.</FONT>
</DL>

<HR>
<A HREF="tutorial025.html"><IMG SRC ="previous_motif.gif" ALT="Previous"></A>
<A HREF="tutorial023.html"><IMG SRC ="contents_motif.gif" ALT="Up"></A>
<A HREF="tutorial027.html"><IMG SRC ="next_motif.gif" ALT="Next"></A>
</BODY>
</HTML>
